FROM alpine:latest
MAINTAINER alex <337676558@qq.com>
ENV NGINX_VERSION 1.12.2
ENV NGINX_WORKSPACE /server/nginx
ENV CONFIG "\
        --prefix=/server/nginx \
        --sbin-path=$NGINX_WORKSPACE/sbin/nginx \
        --conf-path=$NGINX_WORKSPACE/conf/nginx.conf \
        --error-log-path=$NGINX_WORKSPACE/log/error.log \
        --http-log-path=$NGINX_WORKSPACE/log/access.log \
        --pid-path=/var/run/nginx.pid \
        --lock-path=/var/run/nginx.lock \
        --http-client-body-temp-path=/var/cache/nginx/client_temp \
        --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
        --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
        --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
        --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
        --user=www \
        --group=www \
        --with-http_ssl_module \
        --with-http_realip_module \
        --with-http_addition_module \
        --with-http_sub_module \
        --with-http_dav_module \
        --with-http_flv_module \
        --with-http_mp4_module \
        --with-http_gunzip_module \
        --with-http_gzip_static_module \
        --with-http_random_index_module \
        --with-http_secure_link_module \
        --with-http_auth_request_module \
        --with-mail \
        --with-mail_ssl_module \
        --with-file-aio \
        --with-http_v2_module \
        --with-ipv6 \
 "
#ADD repositories /etc/apk/repositories 仓库直接采用国内阿里云

RUN \
    echo -e "https://mirrors.aliyun.com/alpine/latest-stable/main\nhttps://mirrors.aliyun.com/alpine/latest-stable/community" > /etc/apk/repositories \
    &&addgroup -S www \
    && adduser -D -S -h /var/cache/nginx -s /sbin/nologin -G www www \
    && apk add --no-cache --virtual .build-deps \
        gcc \
        libc-dev \
        make \
        openssl-dev \
        pcre-dev \
        zlib-dev \
        linux-headers \
        curl \
        jemalloc-dev \
    && curl "http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz" -o nginx.tar.gz \
    && mkdir -p /usr/src \
    && tar -zxC /usr/src -f nginx.tar.gz \
    && rm nginx.tar.gz \
 #   && cd ../../../ \
    && cd /usr/src/nginx-$NGINX_VERSION \
    && ./configure $CONFIG --with-debug \
    && make \
    && mv objs/nginx objs/nginx-debug \
    && ./configure $CONFIG \
    && make \
    && make install \
    && rm -rf /etc/nginx/html/ \
    && mkdir -p /server/conf/vhosts \
    && mkdir -p $NGINX_WORKSPACE/log/ \
    && mkdir -p $NGINX_WORKSPACE/html/ \
    && mkdir -p $NGINX_WORKSPACE/conf/html/ \
    && install -m644 html/index.html $NGINX_WORKSPACE/html/ \
    && install -m644 html/50x.html $NGINX_WORKSPACE/html/ \
    && install -m755 objs/nginx-debug $NGINX_WORKSPACE/sbin/nginx-debug \
    && strip $NGINX_WORKSPACE/sbin/nginx* \
    && runDeps="$( \
        scanelf --needed --nobanner $NGINX_WORKSPACE/sbin/nginx \
            | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \
            | sort -u \
            | xargs -r apk info --installed \
            | sort -u \
    )" \
    && apk add --virtual .nginx-rundeps $runDeps \
    && apk del .build-deps \
    && rm -rf /usr/src/nginx-$NGINX_VERSION \
    && apk add --no-cache gettext \
    \
    # forward request and error logs to docker log collector
    && ln -sf /dev/stdout $NGINX_WORKSPACE/log/access.log \
    && ln -sf /dev/stderr $NGINX_WORKSPACE/log/error.log

COPY ./conf/nginx.conf $NGINX_WORKSPACE/conf/nginx.conf
#COPY nginx.vh.default.conf /etc/nginx/conf.d/default.conf

EXPOSE 80 443

CMD ["/server/nginx/sbin/nginx", "-g", "daemon off;"]
